home *** CD-ROM | disk | FTP | other *** search
/ BBS in a Box 3 / BBS in a box - Trilogy III.iso / Files / Prog / N-P / NIFTY / myCShell / help.c < prev    next >
Encoding:
C/C++ Source or Header  |  1991-12-30  |  7.6 KB  |  335 lines  |  [TEXT/KAHL]

  1. /*********************************************************
  2.  "help.c"
  3.  
  4.  by John A. Love, III [ Washington Apple Pi Users' Group]
  5.  
  6.  using Symantec's "THINK C", v 5.00
  7.  *********************************************************/
  8.  
  9.  
  10. #ifndef __BALLOONS__
  11. #include <Balloons.h>
  12. #endif
  13.  
  14. #ifndef __GESTALTEQU__
  15. #include <GestaltEqu.h>
  16. #endif
  17.  
  18. #include "protos"
  19.  
  20. #include "globals.h"
  21. #include "extern.h"
  22.  
  23. #include "about.h"
  24. #include "floatingWindow.h"
  25.  
  26.  
  27. // Local prototypes:
  28.  
  29. OSErr    ShowMyNewBalloon (Rect        *altRect,
  30.                           Ptr        tipProc,
  31.                           short        strID,
  32.                           short        strIndex,
  33.                           short        theProc,
  34.                           short        variant,
  35.                           short        method);
  36.  
  37.  
  38.         Point                mouse;
  39.         short                notMine = -1;
  40.         extern DialogPtr    helpPtr;
  41.         extern WindowPeek    frontToolWindow,
  42.                             backToolWindow,
  43.                             frontDocWindow;
  44.  
  45.  
  46.  
  47.         
  48. Boolean HelpManagerActive (void)    {
  49.  /* Do we have a machine on which the Help Manager exists ??? */
  50.  
  51.         short        _Gestalt = 0xA1AD;
  52.         long        myFeature;
  53.         Boolean        result;
  54.  
  55.  
  56.     result = false;
  57.     ;
  58.     if (TrapAvailable(_Gestalt))    {
  59.         if (Gestalt(gestaltHelpMgrAttr, &myFeature) == noErr)    {
  60.             if (BitTst(&myFeature, 31 - gestaltHelpMgrPresent))    result = true;
  61.         }
  62.     }
  63.  
  64.     return(result);
  65.     
  66. }    /* HelpManagerActive */
  67.  
  68.  
  69.  
  70. Boolean BalloonsOn (void)    {
  71. /* Has the user selected "Show Balloons" ??? */
  72.  
  73.     return(HelpManagerActive() && HMGetBalloons());
  74.  
  75. }    /* BalloonsOn */
  76.  
  77.  
  78.  
  79. Boolean BalloonShowing (void)    {
  80. /* Is a Balloon currently showing ??? */
  81.  
  82.     return(HelpManagerActive() && HMIsBalloon());
  83.  
  84. }    /* BalloonShowing */
  85.  
  86.  
  87.  
  88. void HideBalloons (Boolean balloonsUp)    {
  89.  
  90.         OSErr    soWhat;
  91.  
  92.  
  93.     if (balloonsUp)    {
  94.         /* Get the daggum monster out of the way !! */
  95.         /* Used "hmSaveBitsNoWindow option" so bits */
  96.         /* are restored withOUT an update Event.    */
  97.         if (BalloonShowing())    soWhat = HMRemoveBalloon();
  98.                 
  99.         /* Okay, I've restored the bits.  However, now   */
  100.         /* I've got to temporarily disable Balloon Help  */
  101.         /* until I leave with a Mouse Up Event or finish */
  102.         /* with whatever:                                */
  103.         soWhat = HMSetBalloons(false);
  104.         ;
  105.         gLastBalloon = -1;
  106.     }    /* "Show Balloons" active */
  107.  
  108. }    /* HideBalloons */
  109.  
  110.  
  111. void ShowBalloons (Boolean balloonsUp)    {
  112. /* NOW !!! I can safely re-enable Balloon Help: */
  113.  
  114.         OSErr    soWhat;
  115.  
  116.  
  117.     if (balloonsUp)    soWhat = HMSetBalloons(true);
  118.  
  119. }    /* ShowBalloons */
  120.  
  121.  
  122.  
  123. void ResetBalloons (Boolean balloonsUp)    {
  124.  
  125.     if (balloonsUp)    ShowBalloons(true);
  126.     else    HideBalloons(HelpManagerActive());
  127.  
  128. }    /* ResetBalloons */
  129.  
  130.  
  131.  
  132. OSErr ShowMyNewBalloon (Rect    *altRect,
  133.                         Ptr        tipProc,
  134.                         short    strID,
  135.                         short    strIndex,
  136.                         short    theProc,
  137.                         short    variant,
  138.                         short    method)        {
  139.  
  140.         HMMessageRecord        helpMsg;
  141.         Point                tip;
  142.         Rect                cyAltRect;
  143.  
  144.  
  145.  /* See comment besides "nil" passed to HMShowBalloon below:
  146.  
  147.     // ... so we don't change the input Rect:
  148.     cyAltRect = *altRect;
  149.     LocalGlobal(&cyAltRect);
  150.  
  151.     // If we centered the tip and the window is partially
  152.     // hidden by, say, a Floating Window, the tip may end
  153.     // up pointing to the Floating Window:
  154.  
  155.  /*
  156.     // Center the tip:
  157.     SetPt(&tip,
  158.           (cyAltRect.right  + cyAltRect.left)/2,
  159.           (cyAltRect.bottom + cyAltRect.top )/2);
  160.  */
  161.      GetMouse(&tip);
  162.      LocalToGlobal(&tip);
  163.     
  164.     // Fill in HMMessageRecord:
  165.     helpMsg.hmmHelpType             = khmmStringRes;
  166.     helpMsg.u.hmmStringRes.hmmResID    = strID;
  167.     helpMsg.u.hmmStringRes.hmmIndex    = strIndex;
  168.     ;
  169.     return ( HMShowBalloon(&helpMsg, tip,
  170.                            nil,            /* If I pass &cyAltRect, the Help Manager
  171.                                            ** will attempt to re-calculate the tip.
  172.                                            ** This is exactly what I do NOT want
  173.                                            ** because of the possibility that a
  174.                                            ** Floating Window may be covering part
  175.                                            ** of a DLOG item in which case the
  176.                                            ** re-calculated tip may end up pointing
  177.                                            ** to the Floating Window.                 */
  178.                            tipProc, theProc, variant, method) );
  179.  
  180. }    /* ShowMyNewBalloon */
  181.  
  182.  
  183.  
  184. void FindAndShowDynamicBalloons (Boolean balloonsUp)    {
  185.  
  186.         short                stdWDEF = 0, defVar = 0;
  187.         short                activeOtherWindow = 1000;
  188.  
  189.         GrafPtr                savePort;
  190.         WindowPtr            inWindow;
  191.         short                i, iType, part;
  192.         Handle                iHandle;
  193.         Rect                iBox, inactiveBox;
  194.         ControlHandle        iCtl;
  195.         Boolean                inHelpRect = false;
  196.         extern ViewMode        Last_Type;
  197.         extern short        Current_Topic;
  198.  
  199.  
  200.      if ( !balloonsUp ||
  201.           EventAvail(updateMask, &gEvent) /* "Switch-A_Roo" problem */ )        {
  202.         gLastBalloon = notMine;
  203.         return;
  204.     }
  205.  
  206.     mouse = gEvent.where;
  207.     part = FindWindow(mouse, &inWindow);
  208.     
  209.     if (part != inContent)        return;
  210.  
  211.     else    {    /* mouse is in a window somewhere */
  212.                 
  213.         GetPort(&savePort);
  214.         SetPort(inWindow);
  215.         
  216.         GlobalToLocal(&mouse);
  217.  
  218.         if ( ((WindowPeek)inWindow)->hilited )    {
  219.             /* mouse in front, or active window */    
  220.             if (inWindow != helpPtr)    {
  221.                 if (gLastBalloon != activeOtherWindow)    {
  222.             
  223.                     /* ... any active NON-Help Window stuff goes here.
  224.                     ** Remember, ALL Tool Windows are active.  Because
  225.                     ** of the nature of these beasts, however, it's
  226.                     ** probably best to let 'hrct' resources
  227.                     ** "do their thing".                                */
  228.                 
  229.                 
  230.                 
  231.                     gLastBalloon = activeOtherWindow;
  232.                 }
  233.             }    /* mouse in some other active window */
  234.         
  235.             else    /* mouse in active Help Window */    {
  236.             
  237.                 for (i = OK_Button; i <= Message_Area*2; i++)
  238.                 {    /* Use the appropriate strings for disabled items: */
  239.                 
  240.                     if ( (i == OK_Button*2) || (i == Topics_Area*2) )
  241.                         // NO Balloons for disabled case:
  242.                         continue;
  243.                         
  244.                     else if ( (i == (Display_Area-1)*2 + 1) &&
  245.                               (Current_Topic != Initial_Picture) )
  246.                         continue;
  247.                         
  248.                     else if ( i == (Next_Button-1)*2 + 1 )        {
  249.                         GetDItem(helpPtr, Next_Button, &iType, &iHandle, &iBox);
  250.                         iCtl = (ControlHandle)iHandle;
  251.                         /* If hidden, skip BOTH strings.
  252.                         ** If de-activated, skip just one: */
  253.                         if ( ((**iCtl).contrlVis == 0) )    {
  254.                             // Skips both because continue does another i++:
  255.                             i++;
  256.                             continue;
  257.                         }
  258.                         else if ( ((**iCtl).contrlHilite == OFF) )
  259.                             continue;
  260.                     }
  261.             
  262.                     else if ( i == (Prev_Button-1)*2 + 1 )        {
  263.                         GetDItem(helpPtr, Prev_Button, &iType, &iHandle, &iBox);
  264.                         iCtl = (ControlHandle)iHandle;
  265.                         if ( ((**iCtl).contrlVis == 0) )    {
  266.                             i++;
  267.                             continue;
  268.                         }
  269.                         else if ( ((**iCtl).contrlHilite == OFF) )
  270.                             continue;
  271.                     }
  272.             
  273.                     else if (i == (Mast_Head-1)*2 + 1)
  274.                         // NO Balloon for enabled case:
  275.                         continue;
  276.             
  277.                     else if (i == (Message_Area-1)*2 + 1)        {
  278.                         if (Last_Type == text)
  279.                             continue;
  280.                         else /* a pict */ if (Current_Topic == Initial_Picture)
  281.                             /* Since the Message_Area is last in the DITL,
  282.                             ** i += 2 would take i beyond its maximum value
  283.                             ** BEFORE being tested by for(...).                */
  284.                             break;
  285.                     }
  286.             
  287.                     inHelpRect = PtInRect(mouse, &gDynamicBalloons[i].dynamicR);
  288.                     if (inHelpRect)    {
  289.                         if (i != gLastBalloon)    {
  290.  
  291.                             if (ShowMyNewBalloon
  292.                                 (
  293.                                     &gDynamicBalloons[i].dynamicR,
  294.                                     nil,
  295.                                     gDynamicBalloons[i].dynamicStrID,
  296.                                     gDynamicBalloons[i].dynamicStrIndex,
  297.                                     stdWDEF,
  298.                                     defVar,
  299.                                     kHMRegularWindow
  300.                                 ) == noErr)        gLastBalloon = i;
  301.                             else                gLastBalloon = notMine;
  302.                             
  303.                         }
  304.                         break    /* out of for-loop */    ;
  305.                     }    /* inHelpRect */
  306.             
  307.                 }    /* for */
  308.                 
  309.                 if (!inHelpRect /* NOT in any of them */ )        {
  310.                     /* I pass "nil" to HMShowBalloon -- see IM6: */
  311.                     (void) HMRemoveBalloon();
  312.                     gLastBalloon = notMine;
  313.                 }
  314.                 
  315.             }    /* else: mouse in active Help Window */
  316.             
  317.         }    /* Cursor in SOME active window */
  318.         
  319.         else    /* Cursor in an inactive window */    {
  320.         
  321.             /* The 'hovr' resource handles this case. */
  322.             
  323.         }    /* Cursor in SOME inactive window */
  324.         
  325.         SetPort(savePort);
  326.  
  327.     }    /* Mouse is somewhere in a window */
  328.                     
  329. }    /* FindAndShowDynamicBalloons */
  330.  
  331.  
  332.  
  333.  
  334. /*    { end file "help.c" }  */
  335.